home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_084 / ed / matchs.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  925b  |  49 lines

  1. #include <stdio.h>
  2. #include "tools.h"
  3.  
  4. /*
  5.  * Compares line and pattern.  Line is a character string while pat
  6.  * is a pattern template made by getpat().
  7.  * Returns:
  8.  *    1. A zero if no match was found.
  9.  *
  10.  *    2. A pointer to the last character satisfing the match
  11.  *       if ret_endp is non-zero.
  12.  *
  13.  *    3. A pointer to the beginning of the matched string if
  14.  *       ret_endp is zero.
  15.  *
  16.  * e.g.:
  17.  *
  18.  *    matchs ("1234567890", getpat("4[0-9]*7), 0);
  19.  * will return a pointer to the '4', while:
  20.  *
  21.  *    matchs ("1234567890", getpat("4[0-9]*7), 1);
  22.  * will return a pointer to the '7'.
  23.  */
  24. char    *
  25. matchs(line, pat, ret_endp)
  26. char    *line;
  27. TOKEN    *pat;
  28. int    ret_endp;
  29. {
  30.  
  31.     char    *rval, *bptr;
  32.  
  33.     bptr = line;
  34.  
  35.     while(*line)
  36.     {
  37.         if ((rval = amatch(line, pat, bptr)) == 0)
  38.         {
  39.             line++;
  40.         } else {
  41.             if(rval > bptr && rval > line)
  42.                 rval--;    /* point to last char matched */
  43.             rval = ret_endp ? rval : line;
  44.             break;
  45.         }
  46.     }
  47.     return (rval);
  48. }
  49.